<template>
	<view>
		<scroll-view scroll-y class="page">
			<cu-custom bgColor="bg-green" :isBack="true">
				<!-- <block slot="backText">返回</block> -->
				<block slot="content">用户详情</block>
				<view slot="right"  @tap="rightClick">编辑</view>
			</cu-custom>
			<!-- list列表 -->
			<view class="cu-list menu">
				<view class="cu-item animation-slide-bottom" :style="[{animationDelay: '0.1s'}]">
					<view class="content">
						<text class="text-grey">头像</text>
					</view>
					<view class="action">
						<view class="cu-avatar round sm" :style="{backgroundImage: 'url(' + personalMsg.avatar + ')'}"></view>
					</view>
				
				</view>
				<view class="cu-item animation-slide-bottom" :style="[{animationDelay: '0.2s'}]">
					<view class="content">
						<text class="text-grey">姓名</text>
					</view>
					<view class="action">
						<text class="text-grey">{{personalMsg.realName}}</text>
					</view>
				</view>
				<view class="cu-item animation-slide-bottom" :style="[{animationDelay: '0.3s'}]">
					<view class="content">
						<text class="text-grey">性别</text>
					</view>
					<view class="action">
						<text class="text-grey">{{personalMsg.sex}}</text>
					</view>
				</view>
			</view>
			
			<view class="cu-list menu">
				<view class="cu-item animation-slide-bottom" :style="[{animationDelay: '0.9s'}]">
					<view class="content">
						<text class="text-grey">手机</text>
					</view>
					<view class="action">
						<text class="text-grey">{{personalMsg.mobilePhone}}</text>
					</view>
				</view>
				<view class="cu-item animation-slide-bottom" :style="[{animationDelay: '1s'}]">
					<view class="content">
						<text class="text-grey">邮箱</text>
					</view>
					<view class="action">
						<text class="text-grey">{{personalMsg.email}}</text>
					</view>
				</view>
			</view>
			
			<view class="cu-list menu">
				<view class="cu-item animation-slide-bottom" :style="[{animationDelay: '1.2s'}]">
					<view class="content">
						<text class="text-grey">身份</text>
					</view>
					<view class="action">
						<text class="text-grey">农户</text>
					</view>
				</view>
				<view class="cu-item animation-slide-bottom" :style="[{animationDelay: '1.3s'}]">
					<view class="content">
						<text class="text-grey">所属单位</text>
					</view>
					<view class="action">
						<text class="text-grey">{{dept.departname}}</text>
					</view>
				</view>
			</view>

		</scroll-view>
	</view>
</template>

<script>
	import api from '@/api/api.js'
	export default {
		data() {
			return {
				 personalMsg:{
					id:'',
					portrait:'',//图像地址
					avatar:'',//转换后图像地址
					realName:'',
					username:'',
					sex:1,
					birthday:'',
					mobilePhone:'',
					email:'',
					departIds:'',
					departname:'',
					
				},
				dept:{
					id:'',
					departname:''
				},
				departUrl:this.$config.apiUrl+"/appUserController/orgInfo",
				userUrl:this.$config.apiUrl+"/appUserController/queryById",
				expertUrl:this.$config.apiUrl+"/expertController/getExpertInfo"
			};
		},
		onLoad() {
			this.getUserInfo()
		},
		methods: {
			rightClick(){
				this.$Router.push({name:'useredit', params:this.personalMsg})
				/* uni.navigateTo({
				    url: '/pages/user/useredit?item='+item
				}); */
			},
			getUserInfo(){
				this.$http.get(this.userUrl,{params:{id:this.$store.getters.userid}}).then(res=> {
					// console.log("用户",res)
					if (res.data.ok) {
						let result =res.data.data
						this.personalMsg.id = result.id
						let avatar=(result.portrait && result.portrait.length > 0)?this.$config.imgUrl+'/'+result.portrait:'/static/avatar_boy.png'
						this.personalMsg.portrait = result.portrait
						this.personalMsg.avatar = avatar
						this.personalMsg.realName = result.realName
						this.personalMsg.username= result.userName
						this.personalMsg.sex = result.sex=='0'?'男':'女'
						this.personalMsg.departIds= result.departid
						this.personalMsg.mobilePhone= result.mobilePhone== null?'无':result.mobilePhone
						this.personalMsg.email= result.email
						this.getDeptInfo();
					}
				}).catch(e=>{
					console.log("请求错误",e)
				})
			},
			getDeptInfo : function(){
				this.$http.get(this.departUrl,{params:{id:this.personalMsg.departIds}}).then(res=>{
					 if (res.data.ok) {
						let dept = res.data.data;
						this.dept=dept;
						this.personalMsg.departname=this.dept.departname;
						// console.log(this.dept);
					}
				}).catch(err => {
					console.log(err);
				});
			},
		}
	}
</script>

<style>
	.page {
		height: 100Vh;
		width: 100vw;
	}

	.page.show {
		overflow: hidden;
	}

	.switch-sex::after {
		content: "\e716";
	}

	.switch-sex::before {
		content: "\e7a9";
	}

	.switch-music::after {
		content: "\e66a";
	}

	.switch-music::before {
		content: "\e6db";
	}
</style>
